<template>
    <LModalTransfer
        :visible="visible"
        :confirmLoading="confirmLoading" 
        :title="title" 
        :width="width"
        :component="selectEmp"
        :columns="columns"
        uniqueField="empNo"
        ref="empTransfer"
        @handleOk="handleOk" 
        @handleCancel="handleCancel">
    </LModalTransfer>
</template>

<script>
import LTree from '@/components/lt/LTree'
import request from '@/utils/request'
import LTable from '@/components/lt/LTable'
import LModalTransfer from '@/components/lt/LModalTransfer'
const selectEmp={
    template:`
        <a-row>
            <a-col :span="10">
                <a-card :bordered="false">
                   <LTree ref="empTree" :treeData="treeData" @onSelect="onSelect"></LTree>
                </a-card>
            </a-col>
            <a-col :span="14">
                <LTable 
                    ref="empList"
                    size="small"
                    rowKey="keyId"
                    :initQuery="initQuery"
                    :formAttributes="formAttributes"
                    :columns="columns"
                    axiosUrl="/SysEmpController/page"
                    :showPagination="true"
                    :showQueryForm="true"
                    :rowSelection="{onChange: onSelectChange }"
                    >
                </LTable>
               
            </a-col>
        </a-row>
    `,
    name:'selectEmp',
    components:{LTree,LTable},
    data(){
        return{
            treeData:[],
            selectedRowKeys:[],
            selectedRows:[],
            initQuery:[{field:'orgNo',val:'-11145452'}],
            columns:[
                {
                    title: '人员编号',
                    dataIndex: 'empNo'
                },
                {
                    title: '人员账号',
                    dataIndex: 'accountNo'
                },
                {
                    title: '人员名称',
                    dataIndex: 'empName'
                },
            ],
            formAttributes:[
                {field:'empName',label:'姓名',component:'input',condition:'like'},
               
            ],
        }
    },
    methods:{
        onSelectChange (selectedRowKeys, selectedRows) {
            this.selectedRowKeys = selectedRowKeys
            this.selectedRows = selectedRows
        },
        onSelect(node) {

            this.initQuery=[{field:'orgNo',val:node.value}],
            this.$nextTick(() => {
                this.$refs['empList'].searchQuery()
            })
        },
        getSelectedRows(){
            return this.selectedRows
        },
        onCancelSelect(){
            this.selectedRowKeys=[]
            this.selectedRows=[]
            this.$refs["empList"].selectedRows=[]
            this.$refs["empList"].selectedRowKeys=[]
        },
        queryOrg(){
            let that =  this
            request({url: '/SysOrgController/queryOrgTreeSelect',method: 'post',data: {}}).then((res)=>{
                if(res.success){
                   that.treeData = res.result
                }else{
                    that.$message.warning(res.message);
                }
            }).finally(() => {
                that.confirmLoading = false;
                //   that.close()
            })
        }
    },
    mounted(){
        this.$nextTick(()=>{
            let that = this;
            //展开所有
             this.$refs.empTree.expandAll();
        })
    },
    created(){
        this.queryOrg();
    }
}




export default {
    name:'empTransfer',
    components:{LModalTransfer},
    data(){
        return{
            width:document.documentElement.clientWidth-208,
            selectEmp,
            title:'人员选择',
            visible:false,
            confirmLoading: false,
            columns:[
                {
                    title: '人员账号',
                    dataIndex: 'accountNo'
                },
                {
                    title: '人员编号',
                    dataIndex: 'empNo'
                },
                {
                    title: '人员名称',
                    dataIndex: 'empName'
                },
            ]
        }
    },
    methods:{
        edit (record) {
            this.visible = true;
        },
        handleOk(dataSource){
            this.$emit('getSelected',dataSource)
            this.visible=false
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
    }
}
</script>